//
//  HWEveryDayTaskProtocol.swift
//  HWanGame
//
//  Created by 王昌健 on 2022/6/21.
//  Copyright © 2022 94hwan. All rights reserved.
//

import UIKit

class HWEveryDayTaskProtocol: NSObject {
    var model:HWEveryDayTaskModel?
    var didClickRightButton:((_:HWEveryDayTaskDayModel)->())?
    var scrollDidScroll:((_:UIScrollView)->())?
}

extension HWEveryDayTaskProtocol:UITableViewDelegate,UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let header = HWEveryDayTaskHeader.headerOrFooterWithTableView(tableView: tableView)
        return header
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        if section == 1 {
            return 38*widthScale
        }
        return 0
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 2
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if section == 0 {
            return model?.day.count ?? 0
        } else if section == 1 {
            return model?.xinshou.count ?? 0
        } else {
            return 0
        }
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let everyCell = HWEveryDayTaskCell.cellWithTableView(tableView: tableView)
        everyCell.indexPath = indexPath
        if indexPath.section == 0 {
            everyCell.model = model?.day[indexPath.row]
        } else {
            everyCell.model = model?.xinshou[indexPath.row]
        }
        everyCell.didClickRightButton = {
            self.didClickRightButton?($0)
        }
        return everyCell
    }
    
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        self.scrollDidScroll?(scrollView)
    }
 
}
